package com.pie4cloud.pie.job.biz.gather.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.common.log.annotation.SysLog;
import com.pie4cloud.pie.job.api.entity.ConfigGather;
import com.pie4cloud.pie.job.biz.gather.service.ConfigGatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author feilei
 * @date 2022-01-10 00:54:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/configgather" )
@Api(value = "configgather", tags = "管理")
public class ConfigGatherController {

    private final ConfigGatherService configGatherService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param configGather 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('gather_configgather_get')" )
    public R getConfigGatherPage(Page page, ConfigGather configGather) {
        return R.ok(configGatherService.page(page, Wrappers.query(configGather)));
    }

	/**
	 * 查询所有
	 * @return
	 */
	@ApiOperation(value = "查询所有", notes = "查询所有")
	@GetMapping("/list" )
	@PreAuthorize("@pms.hasPermission('gather_configgather_get')" )
	public R list() {
		return R.ok(configGatherService.list());
	}


    /**
     * 通过id查询
     * @param gatherId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{gatherId}" )
    @PreAuthorize("@pms.hasPermission('gather_configgather_get')" )
    public R getById(@PathVariable("gatherId" ) Long gatherId) {
        return R.ok(configGatherService.getById(gatherId));
    }

    /**
     * 新增
     * @param configGather 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('gather_configgather_add')" )
    public R save(@RequestBody ConfigGather configGather) {
		boolean save = configGatherService.save(configGather);
		if (save) {
			return R.ok(configGather);
		}else {
			return R.failed("新增失败");
		}
    }

    /**
     * 修改
     * @param configGather 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('gather_configgather_edit')" )
    public R updateById(@RequestBody ConfigGather configGather) {
        return R.ok(configGatherService.updateById(configGather));
    }

    /**
     * 通过id删除
     * @param gatherId id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除" )
    @DeleteMapping("/{gatherId}" )
    @PreAuthorize("@pms.hasPermission('gather_configgather_del')" )
    public R removeById(@PathVariable Long gatherId) {
        return R.ok(configGatherService.removeById(gatherId));
    }

}
